package com.yuanfeng.base.controller;

import com.yuanfeng.base.vo.ManageExpressQueryVO;
import com.yuanfeng.commoms.dto.base.BaseExpressDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ResponseResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName BaseExpressController
 * @Description 快递
 * @Author hyq
 * @Date 2023/6/19 16:29
 * @Version 1.0
 **/
@RestController
@RequestMapping("/base/express")
public class BaseExpressController extends BaseController{

    /**
     * 查询快递公司
     *
     * @return
     */
    @PostMapping("/query/noToken")
    public ResponseResult queryNoToken() {

        return baseExpressService.queryNoToken();
    }

    /**
     * 查询快递公司列表
     *
     * @param map
     * @return
     */
    @PostMapping("/list/query")
    public ResponseResult queryExpressList(@RequestBody Map<String, Object> map) {

        return baseExpressService.queryExpressList(map);
    }

    /**
     * 根据id查询快递信息
     *
     * @param expressId
     * @return
     */
    @GetMapping("/getInfoById")
    public ResponseResult getBaseExpressInfoById(@RequestParam("expressId") Integer expressId) {

        return baseExpressService.getBaseExpressInfoById(expressId);
    }

    /**
     * 查询快递公司 feign
     *
     * @return
     */
    @PostMapping("/query/noTokenTwo")
    public List<ManageExpressQueryVO> queryNoTokenTwo() {
        return baseExpressService.queryNoTokenTwo();
    }


    /**
     * 新增快递公司
     *
     * @param baseExpressReq
     * @return
     */
    @PostMapping("/add")
    public ResponseResult addExpress(@RequestBody BaseExpressDTO baseExpressReq) {
        if (baseExpressReq == null) {
            return ResponseResult.fail(BizCodeEnume.MISSING_PARAMETER);
        } else if (baseExpressReq.getExpressName().length() > 30) {
            return ResponseResult.fail(BizCodeEnume.EXPRESS_NAME_PING_LIMIT);
        } else if (baseExpressReq.getExpressPinyin().length() > 30) {
            return ResponseResult.fail(BizCodeEnume.EXPRESS_NAME_PING_LIMIT);
        }
        ResponseResult result=baseExpressService.addExpress(baseExpressReq);
        return result;
    }

    /**
     * 修改快递公司
     *
     * @param baseExpressReq
     * @return
     */
    @PostMapping("/update")
    public ResponseResult updateExpress(@RequestBody BaseExpressDTO baseExpressReq) {
        ResponseResult result=baseExpressService.updateExpress(baseExpressReq);
        return result;
    }

    /**
     * 删除快递公司
     *
     * @param baseExpressReq
     * @return
     */
    @PostMapping("/delete")
    public ResponseResult deleteExpress(@RequestBody BaseExpressDTO baseExpressReq) {

        ResponseResult result=baseExpressService.deleteExpress(baseExpressReq);
        return result;
    }

    /**
     * 查询快递设置
     * @param paraMap
     * @return
     */
    @PostMapping("/queryByShopDpexpress")
    public ResponseResult queryByShopDpexpress(@RequestBody Map<String, Object> paraMap) {
        return baseExpressService.queryByShopDpexpress(paraMap);
    }

    /**
     * 更新快递设置
     * @param paraMap
     * @return
     */
    @PostMapping("/updateShopDpexpress")
    public ResponseResult updateShopDpexpress(@RequestBody Map<String,Object> paraMap) {
        return baseExpressService.updateShopDpexpress(paraMap);
    }

    /**
     * 删除快递设置
     * @param paraMap
     * @return
     */
    @PostMapping("/deleteDpexpressParam")
    public ResponseResult deleteDpexpressParam(@RequestBody Map<String,Object> paraMap) {
        return baseExpressService.deleteDpexpressParam(paraMap);
    }

    /**
     * 添加网点密钥
     * @param paraMap
     * @return
     */
    @PostMapping("/insertShopDpexpress")
    public ResponseResult insertshopDpexpress(@RequestBody Map<String,Object> paraMap) {
        return baseExpressService.insertshopDpexpress(paraMap);
    }


    /**
     * 根据选择的快递，动态生成填写信息
     * @param paraMap
     * @return
     */
    @PostMapping("/queryKdiniaoExperss")
    public ResponseResult queryKdiniaoExperss(@RequestBody Map<String,Object> paraMap) {
        return baseExpressService.queryKdiniaoExperss(paraMap);
    }

    /**
     * 根据物流公司Id查找名称
     * @param orderShippingExpressId
     * @return
     */
    @GetMapping("/queryBaseExpressById")
    public String queryBaseExpressById(@RequestParam("orderShippingExpressId") Integer orderShippingExpressId){
        return baseExpressService.queryBaseExpressById(orderShippingExpressId);
    }
}
